/**
* copyright (c) 2017-2023 厦门风领科技有限公司
* https://www.fengling.cn/
* 
* API定义
* zengbinsi
* 2021-10-20 12:01:51
* 2023-10-23 15:30:41
*/

console.log('[TS-API] ========================================================================');
console.log('[TS-API] ');
console.log('[TS-API] API文档：', 'https://developers.weixin.qq.com/minigame/dev/api/');
console.log('[TS-API] ');
console.log('[TS-API] ========================================================================');
console.log('[TS-API] ===>>>', 'Load API declare.');
window.gg = window.gg || {};
/** 框架版本号 */
gg.version = '1.1.0';
gg.isLayaAir = () => { return !!window['Laya'] || false; };
gg.isOtherEngine = () => { return !window.cc || false; };

if (gg.isOtherEngine()) {
    console.log('[TS-API] ===>>>', 'Adapter other engine API.');
    window.cc = window.cc || {};
    window.cc.sys = window.cc.sys || {};
    cc.sys.OS_IOS = 'iOS';
    cc.sys.OS_ANDROID = 'Android';

    cc.debug = { setDisplayStats: (isDisplay) => {} };
}

if (gg.isLayaAir()) {
    console.log('[TS-API] ===>>>', 'Adapter LayaAir engine API.');
    // 本地化存储适配LayaAir引擎
    
    cc.sys.localStorage = cc.sys.localStorage || Laya.LocalStorage;

    // 常量配置
    cc.sys.OS_IOS = 'iOS';
    cc.sys.OS_ANDROID = 'Android';
    if (typeof conchConfig != "undefined") {
        cc.sys.os = conchConfig.getOS() == "Conch-ios" ? cc.sys.OS_IOS : cc.sys.OS_ANDROID;
    }
    if (Laya.Browser.window["conch"]) {
        cc.sys.isNative = true;
    } else if (Laya.Browser.onMiniGame || Laya.Browser.onTTMiniGame || Laya.Browser.onTBMiniGame || Laya.Browser.onQQMiniGame || Laya.Browser.onQGMiniGame || Laya.Browser.onVVMiniGame || Laya.Browser.onHWMiniGame || Laya.Browser.onKGMiniGame || Laya.Browser.onBLMiniGame || Laya.Browser.onAlipayMiniGame || Laya.Browser.onBDMiniGame) {
        cc.sys.isNative = cc.sys.isBrowser = false;
    } else if (window.location && window.location.href) {
        cc.sys.isBrowser = true;
    }
}

// gg.systemEvent 兼容
(function() {
    gg.systemEvent = gg.systemEvent || {};
    const events = {};
    gg.systemEvent.on = (eventName, callback, target) => {
        if (!events[eventName]) { events[eventName] = []; }
        events[eventName].push({ target, callback });
    };
    gg.systemEvent.off = (eventName, callback, target) => {
        if (!events[eventName]) { return; }
        events[eventName] = events[eventName].filter(item => { return item.target !== target || item.callback !== callback; });
    };
    gg.systemEvent.emit = (eventName, ...params) => {
        if (!events[eventName]) { return; }
        events[eventName].forEach(item => { item.callback.apply(item.target, params); });
    };
})();

// 函数定义
(function() {
    gg.isValid = cc.isValid;
})();



gg._audioClips = [];

gg._gameStartTime = Date.now();
/** 游戏开始时间 */
gg.gameStartTime = () => { return Math.floor(gg._gameStartTime / 1000); };
/** 游戏运行时长 */
gg.getRunTime = (isMS) => {
    const runTime = Date.now() - gg._gameStartTime;
    return isMS ? runTime : Math.floor(runTime / 1000);
};
gg.getAppId = () => {
    return window.APP_ID || (window.AppConfig ? window.AppConfig.APP_ID : undefined);
};

// 系统信息
gg.getSystemInfoSync = gg.getSystemInfoSync || (() => { gg.log('该平台暂未实现gg.getSystemInfoSync()方法。'); });
gg.getSystemInfoASync = gg.getSystemInfoASync || (() => { gg.log('该平台暂未实现gg.getSystemInfoASync()方法。'); });
gg.getSystemInfo = gg.getSystemInfo || ((data) => { gg.log('该平台暂未实现gg.getSystemInfo()方法。'); });

// 更新
/** 更新宿主App */
gg.updateApp = gg.updateApp || (() => { });
gg.updateWeChatApp = gg.updateWeChatApp || ((data) => { gg.log('该平台暂未实现gg.updateWeChatApp()方法。'); });
gg.getUpdateManager = gg.getUpdateManager || (() => { gg.log('该平台暂未实现gg.getUpdateManager()方法。'); });
gg.checkUpdateVersion = gg.checkUpdateVersion || (() => { gg.log('该平台暂未实现gg.checkUpdateVersion()方法。'); });

// 应用级事件
gg.onShow = gg.onShow || ((callback) => {
    if (gg.isOtherEngine()) {

    } else {
        cc.game && cc.game.on && cc.game.on(cc.game.EVENT_SHOW, callback);
    }
});
gg.offShow = gg.offShow || ((callback) => {
    if (gg.isOtherEngine()) {

    } else {
        cc.game && cc.game.off && cc.game.off(cc.game.EVENT_SHOW, callback);
    }
});
// 当游戏被挂起到后台时，Creator会分发游戏隐藏事件
gg.onHide = gg.onHide || ((callback) => {
    if (gg.isOtherEngine()) {

    } else {
        cc.game && cc.game.on && cc.game.on(cc.game.EVENT_HIDE, callback);
    }
});
gg.offHide = gg.offHide || ((callback) => {
    if (gg.isOtherEngine()) {

    } else {
        cc.game && cc.game.off && cc.game.off(cc.game.EVENT_HIDE, callback);
    }
});
gg.onError = gg.onError || ((callback) => { gg.log('该平台暂未实现gg.onError()方法。'); });
gg.offError = gg.offError || ((callback) => { gg.log('该平台暂未实现gg.offError()方法。'); });

gg.getLaunchOptionsSync = gg.getLaunchOptionsSync || (() => {
    return { query: {}, referrerInfo: {}, };
});
gg.getEnterOptionsSync = gg.getEnterOptionsSync || (() => { gg.log('该平台暂未实现gg.getEnterOptionsSync()方法。'); });
gg.onUnhandledRejection = gg.onUnhandledRejection || ((callback) => { gg.log('该平台暂未实现gg.onUnhandledRejection()方法。'); });
gg.openAppStoreWithAppId = gg.openAppStoreWithAppId || ((data) => { gg.log('该平台暂未实现gg.openAppStoreWithAppId()方法。'); });
gg.navigateToMiniProgram = gg.navigateToMiniProgram || ((data) => { gg.log('该平台暂未实现gg.navigateToMiniProgram()方法。'); });
gg.onMoreGamesModalClose = gg.onMoreGamesModalClose || (() => { gg.log('该平台暂未实现gg.onMoreGamesModalClose()方法。'); });
gg.onNavigateToMiniProgram = gg.onNavigateToMiniProgram || (() => { gg.log('该平台暂未实现gg.onNavigateToMiniProgram()方法。'); });
gg.exitMiniProgram = gg.exitMiniProgram || ((data) => { gg.log('该平台暂未实现gg.exitMiniProgram()方法。'); });
gg.exitApp = gg.exitApp || ((data) => { gg.log('该平台暂未实现gg.exitApp()方法。'); });

// 其它
gg.getUserCryptoManager = gg.getUserCryptoManager || (() => { gg.log('该平台暂未实现gg.getUserCryptoManager()方法。'); });
/** 游戏对局回放功能 */
gg.getGameRecorderManager = gg.getGameRecorderManager || (() => { gg.log('该平台暂未实现gg.getGameRecorderManager()方法。'); });
gg.onPageStart = gg.onPageStart || ((pageName) => { gg.log('该平台暂未实现gg.onPageStart()方法。'); });
gg.onPageEnd = gg.onPageEnd || ((pageName) => { gg.log('该平台暂未实现gg.onPageEnd()方法。'); });
gg.onProfileSignIn = gg.onProfileSignIn || ((userId) => { gg.log('该平台暂未实现gg.onProfileSignIn()方法。'); });
gg.onProfileSignOff = gg.onProfileSignOff || ((userId) => { gg.log('该平台暂未实现gg.onProfileSignOff()方法。'); });

// UI
gg.showToast = gg.showToast || ((data) => { gg.log('该平台暂未实现gg.showToast()方法。'); });
gg.showModal = gg.showModal || ((data) => { gg.log('该平台暂未实现gg.showModal()方法。'); });
gg.showLoading = gg.showLoading || ((data) => { gg.log('该平台暂未实现gg.showLoading()方法。'); });
gg.hideToast = gg.hideToast || ((data) => { gg.log('该平台暂未实现gg.hideToast()方法。'); });
gg.hideLoading = gg.hideLoading || ((data) => { gg.log('该平台暂未实现gg.hideLoading()方法。'); });

// 网络
gg.request = gg.request || ((data) => { gg.log('该平台暂未实现gg.request()方法。'); });
gg.downloadFile = gg.downloadFile || ((data) => { gg.log('该平台暂未实现gg.downloadFile()方法。'); });
gg.uploadFile = gg.uploadFile || ((data) => { gg.log('该平台暂未实现gg.uploadFile()方法。'); });

// 文件和存储
gg.saveFileToDisk = gg.saveFileToDisk || ((data) => { gg.log('该平台暂未实现gg.saveFileToDisk()方法。'); });
gg.getFileSystemManager = gg.getFileSystemManager || (() => { gg.log('该平台暂未实现gg.getFileSystemManager()方法。'); });
gg.getFileInfo = gg.getFileInfo || ((data) => { gg.log('该平台暂未实现gg.getFileInfo()方法。'); });

gg.getStorageSync = gg.getStorageSync || ((key, encrypt) => {
    return new Promise((resolve, reject) => {
        try {
            const res = cc.sys.localStorage.getItem(key);
            resolve({ data: res });
        } catch (error) {
            reject(error);
        }
    });
});
gg.getStorage = gg.getStorage || ((obj) => {
    return gg.getStorageSync(obj.key, obj.encrypt).then((res) => {
        obj.success && obj.success(res);
        obj.complete && obj.complete();
    }).catch((err) => {
        obj.fail && obj.fail(err);
        obj.complete && obj.complete();
    });
});

gg.setStorageSync = gg.setStorageSync || ((key, data, encrypt) => {
    return new Promise((resolve, reject) => {
        try {
            cc.sys.localStorage.setItem(key, data);
            resolve();
        } catch (error) {
            reject(error);
        }
    });
});
gg.setStorage = gg.setStorage || ((obj) => {
    return gg.setStorageSync(obj.key, obj.data, obj.encrypt).then(() => {
        obj.success && obj.success();
        obj.complete && obj.complete();
    }).catch((err) => {
        obj.fail && obj.fail(err);
        obj.complete && obj.complete();
    });
});

gg.removeStorageSync = gg.removeStorageSync || ((key) => {
    return new Promise((resolve, reject) => {
        try {
            cc.sys.localStorage.removeItem(key);
            resolve({ msg: 'ok' });
        } catch (error) {
            reject(error);
        }
    });
});
gg.removeStorage = gg.removeStorage || ((obj) => {
    return gg.removeStorageSync(obj.key).then((res) => {
        obj.success && obj.success(res);
        obj.complete && obj.complete();
    }).catch((err) => {
        obj.fail && obj.fail(err);
        obj.complete && obj.complete();
    });
});

gg.clearStorageSync = gg.clearStorageSync || ((obj) => {
    return new Promise((resolve, reject) => {
        try {
            cc.sys.localStorage.clear();
            resolve({ msg: 'ok' });
        } catch (error) {
            reject(error);
        }
    });
});
gg.clearStorage = gg.clearStorage || ((obj) => {
    return gg.clearStorageSync(obj.key).then((res) => {
        obj.success && obj.success(res);
        obj.complete && obj.complete();
    }).catch((err) => {
        obj.fail && obj.fail(err);
        obj.complete && obj.complete();
    });
});

// 开放接口
gg.login = gg.login || ((data) => { gg.log('该平台暂未实现gg.login()方法。'); });
gg.checkSession = gg.checkSession || ((data) => { gg.log('该平台暂未实现gg.checkSession()方法。'); });
gg.authorize = gg.authorize || ((data) => { gg.log('该平台暂未实现gg.authorize()方法。'); });
/** 防沉迷校验 */
gg.checkIsUserAdvisedToRest = gg.checkIsUserAdvisedToRest || ((data) => { gg.log('该平台暂未实现gg.checkIsUserAdvisedToRest()方法。'); });

// 设备
gg.getBatteryInfoSync = gg.getBatteryInfoSync || (() => { gg.log('该平台暂未实现gg.getBatteryInfoSync()方法。'); });
gg.getBatteryInfo = gg.getBatteryInfo || ((data) => { gg.log('该平台暂未实现gg.getBatteryInfo()方法。'); });
gg.setClipboardData = gg.setClipboardData || ((data) => { gg.log('该平台暂未实现gg.setClipboardData()方法。'); });
gg.getClipboardData = gg.getClipboardData || ((data) => { gg.log('该平台暂未实现gg.getClipboardData()方法。'); });
gg.onNetworkWeakChange = gg.onNetworkWeakChange || ((data) => { gg.log('该平台暂未实现gg.onNetworkWeakChange()方法。'); });
gg.getNetworkType = gg.getNetworkType || ((data) => { gg.log('该平台暂未实现gg.getNetworkType()方法。'); });
gg.onNetworkWeakChange = gg.onNetworkWeakChange || ((data) => { gg.log('该平台暂未实现gg.onNetworkWeakChange()方法。'); });
gg.getLocalIPAddress = gg.getLocalIPAddress || ((data) => { gg.log('该平台暂未实现gg.getLocalIPAddress()方法。'); });
gg.setScreenBrightness = gg.setScreenBrightness || ((data) => { gg.log('该平台暂未实现gg.setScreenBrightness()方法。'); });
gg.getScreenBrightness = gg.getScreenBrightness || ((data) => { gg.log('该平台暂未实现gg.getScreenBrightness()方法。'); });
gg.setKeepScreenOn = gg.setKeepScreenOn || ((data) => { gg.log('该平台暂未实现gg.setKeepScreenOn()方法。'); });
gg.getLocalIPAddress = gg.getLocalIPAddress || ((data) => { gg.log('该平台暂未实现gg.getLocalIPAddress()方法。'); });
gg.vibrateShort = gg.vibrateShort || ((data) => { gg.log('该平台暂未实现gg.vibrateShort()方法。'); });
gg.vibrateLong = gg.vibrateLong || ((data) => { gg.log('该平台暂未实现gg.vibrateLong()方法。'); });
gg.createUserInfoButton = gg.createUserInfoButton || ((data) => { gg.log('该平台暂未实现gg.createUserInfoButton()方法。'); });

// 广告
gg.createRewardedVideoAd = gg.createRewardedVideoAd || ((data) => { gg.log('该平台暂未实现gg.createRewardedVideoAd()方法。'); });
gg.createInterstitialAd = gg.createInterstitialAd || ((data) => { gg.log('该平台暂未实现gg.createInterstitialAd()方法。'); });
gg.createGridAd = gg.createGridAd || ((data) => { gg.log('该平台暂未实现gg.createGridAd()方法。'); });
gg.createCustomAd = gg.createCustomAd || ((data) => { gg.log('该平台暂未实现gg.createCustomAd()方法。'); });
gg.createBannerAd = gg.createBannerAd || ((data) => { gg.log('该平台暂未实现gg.createBannerAd()方法。'); });
gg.createInterstitialAd = gg.createInterstitialAd || ((data) => { gg.log('该平台暂未实现gg.createInterstitialAd()方法。'); });
/** 创建原生广告 */
gg.createNativeAd = gg.createNativeAd || ((data) => { gg.log('该平台暂未实现gg.createNativeAd()方法。'); });
/** 创建盒子广告 */
gg.createAppBox = gg.createAppBox || ((data) => { gg.log('该平台暂未实现gg.createAppBox()方法。'); });

// 转发
/** 更新转发属性 */
gg.updateShareMenu = gg.updateShareMenu || ((data) => { gg.log('该平台暂未实现gg.updateShareMenu()方法。'); });
/** 显示当前页面的转发按钮 */
gg.showShareMenu = gg.showShareMenu || ((data) => { gg.log('该平台暂未实现gg.showShareMenu()方法。'); });
gg.hideShareMenu = gg.hideShareMenu || ((data) => { gg.log('该平台暂未实现gg.hideShareMenu()方法。'); });
/** 主动拉起转发，进入选择通讯录界面 */
gg.shareAppMessage = gg.shareAppMessage || ((data) => { gg.log('该平台暂未实现gg.shareAppMessage()方法。'); });
/** 监听用户点击右上角菜单的「转发」按钮时触发的事件 */
gg.onShareAppMessage = gg.onShareAppMessage || ((callback) => { gg.log('该平台暂未实现gg.onShareAppMessage()方法。'); });
/** 获取转发详细信息 */
gg.getShareInfo = gg.getShareInfo || ((data) => { gg.log('该平台暂未实现gg.getShareInfo()方法。'); });

// 工具函数
/**
 * 是否是空值（null|undefined）
 * @param value 要判空的值
 */
gg.isEmpty = (value) => { return (value === undefined || value === null); };
/**
 * 是否是空值（null|undefined|空字符串）
 * @param value 要判空的值
 */
gg.isEmptyString = (value) => { return (gg.isEmpty(value) || value === ''); };
/**
 * 如果对象为null或者undefined就返回第二个参数的值
 * @param value 要判空的值
 * @param defaultValue 默认返回值
 */
gg.ifnull = (value, defaultValue) => { return value === undefined || value === null ? defaultValue : value; };
/** 文字国际化转换 */
gg.i18nString = (zhString) => { return zhString; };

// 调试
gg.setEnableDebug = gg.setEnableDebug || ((data) => { gg.log('该平台暂未实现gg.setEnableDebug()方法。'); });
gg.getRealtimeLogManager = gg.getRealtimeLogManager || (() => { gg.log('该平台暂未实现gg.getRealtimeLogManager()方法。'); });
gg.getLogManager = gg.getLogManager || ((data) => { gg.log('该平台暂未实现gg.getLogManager()方法。'); });

const gg_log = console.log;
const gg_info = console.info;
const gg_debug = console.debug;
const gg_warn = console.warn;
const gg_error = console.error;
gg.flog = (...params) => { return gg_log('[TS-API-FRAME] ===>>>', ...params); };
gg.finfo = (...params) => { return gg_info('[TS-API-FRAME] ===>>>', ...params); };
gg.fdebug = (...params) => { return gg_debug('[TS-API-FRAME] ===>>>', ...params); };
gg.fwarn = (...params) => { return gg_warn('[TS-API-FRAME] ===>>>', ...params); };
gg.ferror = (...params) => { return gg_error('[TS-API-FRAME] ===>>>', ...params); };
gg.log = (...params) => { return gg_log('[TS-API] ===>>>', ...params); };
gg.info = (...params) => { return gg_info('[TS-API] ===>>>', ...params); };
gg.debug = (...params) => { return gg_debug('[TS-API] ===>>>', ...params); };
gg.warn = (...params) => { return gg_warn('[TS-API] ===>>>', ...params); };
gg.error = (...params) => { return gg_error('[TS-API] ===>>>', ...params); };
gg.logCallStack = () => { return gg.log(new Error().stack); };

// 新增
gg.getAppVersion = () => { return window.APP_VERSION || (gg.log('该平台暂未实现gg.getAppVersion()方法。'), '1.0.0'); };
gg.parseJSON = (strOrObj) => {
    try {
        if (typeof strOrObj === 'string' && (strOrObj.indexOf('{') === 0 || strOrObj.indexOf('[') === 0 || strOrObj === 'true' || strOrObj === 'false')) {
            return JSON.parse(strOrObj);
        }
        return strOrObj;
    } catch (e) {
        return strOrObj;
    }
};
gg.stringifyJSON = (strOrObj) => { return typeof strOrObj === 'string' ? strOrObj : JSON.stringify(strOrObj); };
gg.openBrowserUrl = (url) => { gg.log('该平台暂未实现gg.openBrowserUrl()方法。'); };
gg.openWebViewUrl = (url) => { gg.log('该平台暂未实现gg.openWebViewUrl()方法。'); };
gg.connectDatabase = (data) => { gg.log('该平台暂未实现gg.connectDatabase()方法。'); };
gg.compareVersion = (v1, v2) => {
    const v1s = v1.split('.') || [];
    const v2s = v2.split('.') || [];
    const maxLen = v1s.length > v2s.length ? v1s.length : v2s.length;
    let _v1, _v2;

    for (let i = 0; i < maxLen; i++) {
        _v1 = Number(v1s[i] || '0');
        _v2 = Number(v2s[i] || '0');

        if (_v1 > _v2) {
            return 1;
        } else if (_v1 < _v2) {
            return -1;
        }
    }
    return 0;
};

gg.setDisplayLogPanel = (isDisplay) => { gg.log('该平台暂未实现gg.setDisplayLogPanel()方法。'); };
gg.shareAppMessage = (data) => { gg.log('该平台暂未实现gg.shareAppMessage()方法。'); };
gg.aldShareAppMessage = (data) => { gg.log('该平台暂未实现gg.aldShareAppMessage()方法。'); };
gg.getMenuButtonBoundingClientRect = () => { gg.log('该平台暂未实现gg.getMenuButtonBoundingClientRect()方法。'); };
gg.postMessage = () => { gg.log('该平台暂未实现gg.postMessage()方法。'); };
gg.getGroupCloudStorage = () => { gg.log('该平台暂未实现gg.getGroupCloudStorage()方法。'); };
gg.loadSubpackage = () => { gg.log('该平台暂未实现gg.loadSubpackage()方法。'); };
gg.createWorker = () => { gg.log('该平台暂未实现gg.createWorker()方法。'); };
gg.openCustomerServiceConversation = (object) => {
    gg.log('该平台暂未实现gg.openCustomerServiceConversation()方法。');
    return new Promise((resolve, reject) => {
        const err = { errMsg: '该平台暂未实现gg.openCustomerServiceConversation()方法。' };
        object && object.fail && object.fail(err);
        object && object.complete && object.complete(err);
        reject(err);
    });
};
gg.createGameClubButton = () => { gg.log('该平台暂未实现gg.createGameClubButton()方法。'); };
gg.getSetting = () => { gg.log('该平台暂未实现gg.getSetting()方法。'); };
gg.getUserInfo = () => { gg.log('该平台暂未实现gg.getUserInfo()方法。'); };
gg.setUserCloudStorage = () => { gg.log('该平台暂未实现gg.setUserCloudStorage()方法。'); };
gg.getFriendCloudStorage = () => { gg.log('该平台暂未实现gg.getFriendCloudStorage()方法。'); };
gg.reportEvent = () => { gg.log('该平台暂未实现gg.reportEvent()方法。'); };
gg.getOpenDataContext = () => { gg.log('该平台暂未实现gg.getOpenDataContext()方法。'); };
gg.triggerGC = () => { gg.log('该平台暂未实现gg.triggerGC()方法。'); };
gg.createContactButton = () => { gg.log('该平台暂未实现gg.createContactButton()方法。'); };
gg.requestSubscribeSystemMessage = () => { gg.log('该平台暂未实现gg.requestSubscribeSystemMessage()方法。'); };
gg.requestSubscribeMessage = () => { gg.log('该平台暂未实现gg.requestSubscribeMessage()方法。'); };
gg.addShortcut = () => { gg.log('该平台暂未实现gg.addShortcut()方法。'); };
gg.openAwemeUserProfile = () => { gg.log('该平台暂未实现gg.openAwemeUserProfile()方法。'); };
gg.checkFollowState = () => { gg.log('该平台暂未实现gg.checkFollowState()方法。'); };
gg.adInit = () => { gg.log('gg.adInit, native平台专用。'); };


gg.env = gg.env || {
    USER_DATA_PATH: '',
};

gg.installShortcut = (object) => { gg.log('该平台暂未实现gg.installShortcut()方法。'); };
gg.hasShortcutInstalled = (object) => { gg.log('该平台暂未实现gg.hasShortcutInstalled()方法。'); };

// Cocos 专用
gg.getCanvas = () => { return cc.director.getScene().getChildByName('Canvas'); };
gg.convertToTargetSpaceAR = (node, target) => { return target.convertToNodeSpaceAR(node.convertToWorldSpaceAR(cc.v2(0, 0))); };
gg.loadBundle = (bundleName, callback) => {
    return new Promise((resolve, reject) => {
        cc.assetManager.loadBundle(bundleName, (err, bundle) => {
            if (err) {
                callback && callback(err);
                return reject(err);
            }

            callback && callback(undefined, bundle);
            return resolve(bundle);
        });
    });
};
/**加载资源*/
gg.loadAssets = (assets, assetType, callback) => {
    assets = assets.split(':');
    const bundleName = assets[0];
    const url = assets[1];

    return new Promise((resolve, reject) => {
        cc.assetManager.loadBundle(bundleName, (err, bundle) => {
            if (err) {
                callback && callback(err);
                return reject(err);
            }
            bundle.load(url, assetType, (err, asset) => {
                if (err) {
                    callback && callback(err);
                    return reject(err);
                }
                callback && callback(undefined, asset);
                return resolve(asset);
            });
        });
    });
};
gg.showDebug = () => {
    cc.debug.setDisplayStats(true);
    setTimeout(() => {
        const testNode = cc.director.getScene().getChildByName('PROFILER-NODE');
        testNode && (testNode.scale = 2);
    }, 1);
};

gg.getChannel = () => { return 0; };
// 支付
gg.payment = (data) => { gg.log('该平台暂未实现gg.payment()方法。'); };



// bi数据上报
gg.sendEvent = (eventName, params) => { gg.log('该平台暂未实现gg.sendEvent()方法。'); };

// 设置随机种子
Math.seed = Date.now();
Math.random = () => {
    Math.seed = (Math.seed * 9301 + 49297) % 233280;
    return Math.seed / 233280.0;
};